#ifndef _SRC_NET_EVENT_LOOP_THREAD_POOL_H_
#define _SRC_NET_EVENT_LOOP_THREAD_POOL_H_

#include <functional>
#include <memory>
#include <vector>
#include <string>

#include "src/base/utils.h"

namespace fio66::net {
class EventLoop;
class EventLoopThread;

class EventLoopThreadPool {
 public:
  DISALLOW_COPY_AND_ASSIGN(EventLoopThreadPool)
  typedef std::function<void(EventLoop*)> ThreadInitCallback;

  EventLoopThreadPool(EventLoop* baseLoop, const std::string& nameArg);
  ~EventLoopThreadPool();

  void SetThreadNum(int numThreads) { num_threads_ = numThreads; }
  void Start(const ThreadInitCallback& cb = ThreadInitCallback());

  // valid after calling start()
  /// round-robin
  EventLoop* GetNextLoop();

  /// with the same hash code, it will always return the same EventLoop
  EventLoop* GetLoopForHash(size_t hashCode);

  std::vector<EventLoop*> GetAllLoops();

  bool Started() const { return started_; }

  const std::string& Name() const { return name_; }

 private:
  EventLoop* baseLoop_;
  std::string name_;
  bool started_;
  int num_threads_;
  int next_;
  std::vector<std::unique_ptr<EventLoopThread>> threads_;
  std::vector<EventLoop*> loops_;
};
}  // namespace fio66::net

#endif  // _SRC_NET_EVENT_LOOP_THREAD_POOL_H_
